# """
# This is the interface that allows for creating nested lists.
# You should not implement it, or speculate about its implementation
# """
class NestedInteger:
   def __init__(self, value=None):
       """
       If value is not specified, initializes an empty list.
       Otherwise initializes a single integer equal to value.
       """
       self.value = value

   def isInteger(self):
       """
       @return True if this NestedInteger holds a single integer, rather than a nested list.
       :rtype bool
       """
       return type(self.value) is int

   def add(self, elem):
       """
       Set this NestedInteger to hold a nested list and adds a nested integer elem to it.
       :rtype void
       """
       pass

   def setInteger(self, value):
       """
       Set this NestedInteger to hold a single integer equal to value.
       :rtype void
       """
       pass

   def getInteger(self):
       """
       @return the single integer that this NestedInteger holds, if it holds a single integer
       Return None if this NestedInteger holds a nested list
       :rtype int
       """
       return self.value

   def getList(self):
       """
       @return the nested list that this NestedInteger holds, if it holds a nested list
       Return None if this NestedInteger holds a single integer
       :rtype List[NestedInteger]
       """
       return self.value


from typing import List
class Solution:
    def depthSum(self, nestedList: List[NestedInteger]) -> int:
        def solve(pre_depth, nested: NestedInteger):
            if nested.isInteger():
                result = pre_depth * nested.getInteger()
                return result

            result = 0
            for x in nested.getList():
                nested2 = NestedInteger(x)
                result += solve(pre_depth+1, nested2)
            return result

        sum_ = 0
        for x in nestedList:
            nested = NestedInteger(x)
            sum_ += solve(1, nested)
        return sum_


res = Solution().depthSum([[1,2]])
print(res)

res = Solution().depthSum([[1,2],3,[4,5]])
print(res)

res = Solution().depthSum([[1,1],2,[1,1]])
print(res)

res = Solution().depthSum([1,[4,[6]]])
print(res)
